<?php

namespace App\Containers\AppSection\Pledge\UI\API\Transformers\Properties\Contracts;

use App\Containers\AppSection\File\UI\API\Transformers\FileTransformer;
use App\Containers\AppSection\Pledge\Models\Properties\Contracts\Uses;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Collection;

class UsesTransformer extends Transformer
{
    protected array $defaultIncludes = [
        'documents'
    ];

    /**
     * @param Uses $t
     * @return array
     */
    public function transform(Uses $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'address' => $t->address,
            'number' => $t->number,
            'total_area_type' => $t->total_area_type,
            'total_area' => $t->total_area,
            'land_category' => $t->land_category,
            'permitted_use' => $t->permitted_use,
            'other_information' => $t->other_information,
            'uses_type' => $t->uses_type,
            'uses' => $t->uses,
            'rent_confirmed' => $t->rent_confirmed,
            'contract_name' => $t->contract_name,
            'contract_date' => $this->dateFormatter($t->contract_date),
            'contract_number' => $t->contract_number,
            'contract_tenant' => $t->contract_tenant,
            'contract_registered_date' => $this->dateFormatter($t->contract_registered_date),
            'contract_registered_company' => $t->contract_registered_company,
            'contract_registered_number' => $t->contract_registered_number,
            'order_company' => $t->order_company,
            'order_number' => $t->order_number,
            'order_date' => $this->dateFormatter($t->order_date),
        ];
    }

    public function includeDocuments(Uses $t): Collection
    {
        return $this->collection($t->documents()->get(), new FileTransformer);
    }
}
